using System;
using Common.Unity.Extensions.PropertyMapper.Policies;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;

namespace Common.Unity.Extensions.PropertyMapper
{
	class PropertyMappingPolicyInjection : InjectionMember
	{
		readonly Type sourceType;
		readonly IPropertyMappingPolicy policy;

		public PropertyMappingPolicyInjection( Type sourceType, IPropertyMappingPolicy policy )
		{
			Guard.ArgumentNotNull( sourceType, "sourceType" );
			Guard.ArgumentNotNull( policy, "policy" );
			this.sourceType = sourceType;
			this.policy = policy;
		}

		public override void AddPolicies( Type typeToCreate, string name, IPolicyList list )
		{
			list.Set( policy.GetType(), policy, new PropertyMappingKey( sourceType, new NamedTypeBuildKey( typeToCreate, name ) ) );
		}
	}
}